package com.flydog.taskManager.common.vaildator;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 * @author caoweidong
 * @version 0.0.0
 * @create 2021/6/28 16:51
 */
public class FlagValidatorClass implements ConstraintValidator<FlagValidator, Integer> {
    private int[] values;

    @Override
    public void initialize(FlagValidator constraintAnnotation) {
        this.values = constraintAnnotation.value();
    }

    @Override
    public boolean isValid(Integer value, ConstraintValidatorContext constraintValidatorContext) {
        if (value == null) {
            return true;
        }
        for (int i : values) {
            if (i == value) {
                return true;
            }
        }
        return false;
    }
}
